/*
 * 
 *  This file is part of Sourceprojects.org Lycia Copyright 2010 noctarius
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 */
package org.sourceprojects.lycia.internal.platform.base;

import org.sourceprojects.lycia.annotations.Child;
import org.sourceprojects.lycia.annotations.Parent;
import org.sourceprojects.lycia.internal.logging.LyciaLoggerWrapper;
import org.sourceprojects.lycia.internal.platform.ParameterMatcher;
import org.sourceprojects.lycia.internal.platform.android.AndroidCompatibleParameterMatcherFactoryImpl;

public class ParameterMatcherFactoryImpl extends
		AndroidCompatibleParameterMatcherFactoryImpl {

	private static final LyciaLoggerWrapper LOGGER = LyciaLoggerWrapper
			.getLogger(ParameterMatcherFactoryImpl.class);

	@Override
	public ParameterMatcher[] provideParameterMatchers() {
		final ParameterMatcher[] superParameterMatchers = super
				.provideParameterMatchers();

		try {
			final Class<?> clazz = Class.forName("javax.xml.namespace.QName");

			final int length = superParameterMatchers.length;
			final ParameterMatcher[] parameterMatchers = new ParameterMatcher[length + 3];
			System.arraycopy(superParameterMatchers, 0, parameterMatchers, 0,
					length);

			parameterMatchers[length] = new ParameterMatcher(clazz, Child.class);
			parameterMatchers[length + 1] = new ParameterMatcher(clazz,
					Parent.class);
			parameterMatchers[length + 2] = new ParameterMatcher(clazz);

			return parameterMatchers;
		} catch (final ClassNotFoundException e) {
			LOGGER.warn(
					"javax.xml.namespace.QName wasn't found in Classpath - "
							+ "fallback to a ParameterMatcher without it", e);

			return superParameterMatchers;
		}
	}
}
